﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Wise.Entities;

namespace UploadTools
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string binDir = FileHelper.GetCurrentDirectory();
            string[] files = System.IO.Directory.GetFiles(System.IO.Path.Combine(binDir, "Configs"), "默认配置文件.json", System.IO.SearchOption.AllDirectories);
            if (files.Length > 0)
            {
                try
                {
                    MyDbConfig.Current = new MyDbConfig(files.FirstOrDefault());
                }
                catch (Exception exp)
                {
                    MessageBox.Show($"在加载默认配置文件时,发生{exp.Message}");
                }
            }
            if(MyDbConfig.Current==null)
                MyDbConfig.Current = new MyDbConfig();
            textBox1.Text = MyDbConfig.Current.文件服务器;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(openFileDialog1.ShowDialog()== DialogResult.OK)
            {
                try
                {
                    string fileName = openFileDialog1.FileName;
                    string responseText = HttpHelper.HttpUploadFile(textBox1.Text, fileName, new System.Collections.Specialized.NameValueCollection());
                    textBox2.Text = responseText;
                    //MessageBox.Show($"上传结果:{responseText}");
                }
                catch(Exception exp)
                {
                    MessageBox.Show(exp.Message);
                }
            }
        }
    }
}
